package cn.daniellee.plugin.pm.menu;

import cn.daniellee.plugin.pm.PartnerMission;
import cn.daniellee.plugin.pm.component.ItemGenerator;
import cn.daniellee.plugin.pm.model.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class PlayerMenu {

	public static Inventory generate(Player player) {
		Inventory menu = Bukkit.createInventory(new PlayerMenuHolder(), InventoryType.HOPPER, PartnerMission.getInstance().getConfig().getString("menu.edit.title", "&6&lEdit profile").replace("&", "§"));

		PlayerData playerData = PartnerMission.getInstance().getStorage().getPlayerByName(player.getName());

		if (playerData.isEnabled()) menu.setItem(0, ItemGenerator.getItem(PartnerMission.getInstance().getConfig().getString("menu.edit.button.enable.name", "&a&lNeed partner"), PartnerMission.getInstance().getConfig().getStringList("menu.edit.button.enable.lore"), PartnerMission.getInstance().getConfig().getString("menu.edit.button.enable.item.material", "BEACON"), PartnerMission.getInstance().getConfig().getInt("menu.edit.button.enable.item.durability", 0)));
		else menu.setItem(0, ItemGenerator.getItem(PartnerMission.getInstance().getConfig().getString("menu.edit.button.disable.name", "&a&lNeed partner"), PartnerMission.getInstance().getConfig().getStringList("menu.edit.button.disable.lore"), PartnerMission.getInstance().getConfig().getString("menu.edit.button.disable.item.material", "TNT"), PartnerMission.getInstance().getConfig().getInt("menu.edit.button.disable.item.durability", 0)));

		menu.setItem(2, ItemGenerator.getItem(PartnerMission.getInstance().getConfig().getString("menu.edit.button.contact.name", "&b&lContact information"), new ArrayList<>(List.of("&r" + playerData.getContact())), PartnerMission.getInstance().getConfig().getString("menu.edit.button.contact.item.material", "NAME_TAG"), PartnerMission.getInstance().getConfig().getInt("menu.edit.button.contact.item.durability", 0)));

		menu.setItem(4, ItemGenerator.getItem(PartnerMission.getInstance().getConfig().getString("menu.edit.button.intro.name", "&d&lSelf introduction"), playerData.getIntroduction().stream().map(item -> item = "&r" + item).collect(Collectors.toList()), PartnerMission.getInstance().getConfig().getString("menu.edit.button.intro.item.material", "WRITABLE_BOOK"), PartnerMission.getInstance().getConfig().getInt("menu.edit.button.intro.item.durability", 0)));

		return menu;
	}

	public static class PlayerMenuHolder implements InventoryHolder {
		@Override
		public Inventory getInventory() {
			return Bukkit.createInventory(null, InventoryType.HOPPER);
		}
	}
}
